package com.sz.jinzheng.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sz.jinzheng.mapper.ApplicationResultsMapper;
import com.sz.jinzheng.model.ApplicationResults;
import com.sz.jinzheng.model.PageBean;
import com.sz.jinzheng.service.ApplicationResultsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ApplicationResultsImpl implements ApplicationResultsService {
    @Autowired
    private ApplicationResultsMapper mapper;

    @Override
    public PageBean<ApplicationResults> getApplicationResults(int index, int size) {
        //利用mybatis分页插件来进行分页数据库
        PageHelper.startPage(index, size);
        List<ApplicationResults> results = mapper.getApplicationResults();
        Page<ApplicationResults> page = (Page<ApplicationResults>) results;
        PageBean<ApplicationResults> pageBean = new PageBean<>(page.getTotal(),
                page.getPageSize(), page.getPageNum(), page.getPages(), page.getResult());
        return pageBean;
    }
}
